//    Copyright (C) Kherty.  All rights reserved.
using System;
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing
{
    internal class TableStyle : IOfficeXmlSerializable
    {
        internal const string xmlName = "tableStyle";
        private TablePartStyle _band1H;
        private TablePartStyle _band1V;
        private TablePartStyle _band2H;
        private TablePartStyle _band2V;
        private OfficeArtExtensionList _extLst;
        private TablePartStyle _firstCol;
        private TablePartStyle _firstRow;
        private TablePartStyle _lastCol;
        private TablePartStyle _lastRow;
        private TablePartStyle _neCell;
        private TablePartStyle _nwCell;
        private TablePartStyle _seCell;
        private Guid _styleId;
        private String _styleName;
        private TablePartStyle _swCell;
        private TableBackgroundStyle _tblBg;
        private TablePartStyle _wholeTbl;

        #region IOfficeXmlSerializable Members

        public void ReadXml(ReadContext context)
        {
            using (var c = context.Read(xmlName))
            {
                _styleId = new Guid(c.GetString("styleId"));
                _styleName = c.GetString("styleName");
                _tblBg = c.ReadOptionalElement<TableBackgroundStyle>("tblBg");
                _wholeTbl = c.ReadOptionalElementAs<TablePartStyle>("wholeTbl");
                _band1H = c.ReadOptionalElementAs<TablePartStyle>("band1H");
                _band2H = c.ReadOptionalElementAs<TablePartStyle>("band2H");
                _band1V = c.ReadOptionalElementAs<TablePartStyle>("band1V");
                _band2V = c.ReadOptionalElementAs<TablePartStyle>("band2V");
                _lastCol = c.ReadOptionalElementAs<TablePartStyle>("lastCol");
                _firstCol = c.ReadOptionalElementAs<TablePartStyle>("firstCol");
                _lastRow = c.ReadOptionalElementAs<TablePartStyle>("lastRow");
                _seCell = c.ReadOptionalElementAs<TablePartStyle>("seCell");
                _swCell = c.ReadOptionalElementAs<TablePartStyle>("swCell");
                _firstRow = c.ReadOptionalElementAs<TablePartStyle>("firstRow");
                _neCell = c.ReadOptionalElementAs<TablePartStyle>("neCell");
                _nwCell = c.ReadOptionalElementAs<TablePartStyle>("nwCell");
                _extLst = c.ReadOptionalElement<OfficeArtExtensionList>("extLst");
            }
        }

        public void WriteXml(WriteContext context)
        {
            using (var c = context.Write(xmlName))
            {
                c.SetString("styleId", "{"+_styleId+"}");
                c.SetString("styleName", _styleName);
                c.WriteOptionalElement(_tblBg);
                c.WriteOptionalElementAs(_wholeTbl, "wholeTbl"); //\\\\\\
                c.WriteOptionalElementAs(_band1H, "band1H");
                c.WriteOptionalElementAs(_band2H, "band2H");
                c.WriteOptionalElementAs(_band1V, "band1V");
                c.WriteOptionalElementAs(_band2V, "band2V");
                c.WriteOptionalElementAs(_lastCol, "lastCol");
                c.WriteOptionalElementAs(_firstCol, "firstCol");
                c.WriteOptionalElementAs(_lastRow, "lastRow");
                c.WriteOptionalElementAs(_seCell, "seCell");
                c.WriteOptionalElementAs(_swCell, "swCell");
                c.WriteOptionalElementAs(_firstRow, "firstRow");
                c.WriteOptionalElementAs(_neCell, "neCell");
                c.WriteOptionalElementAs(_nwCell, "nwCell");
                c.WriteOptionalElement(_extLst);
            }
        }

        #endregion
    }
}